package com.topone.controller;

import com.topone.Enum.BussinessStatusEnum;
import com.topone.Exception.FanZoneException;
import com.topone.Utils.ResultVOUntil;
import com.topone.VO.ResultVO;
import com.topone.dataObject.Bussiness;
import com.topone.dto.BussinessDTO;
import com.topone.service.BussinessService;
import lombok.extern.slf4j.Slf4j;
import org.omg.CORBA.OBJ_ADAPTER;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2018/2/3,0003.
 */
@CrossOrigin
@RestController
@RequestMapping("/test")
@Slf4j
public class TestController {

    @Autowired
    private BussinessService bussinessService;

    @GetMapping("/json")
    public ResultVO<Map<String,Object>> list(Map<String,Object>  map){
        map.put("openid","oeeRzxLaCin4AcZ5_K7ie7S5KPng");
        log.info("openid={}",map);
        return ResultVOUntil.success(map);
    }

    @GetMapping("/list")
    public ResultVO<Map<String,Object>> bussinessList(Map<String,Object> map,@RequestParam("id") String id){
        List<BussinessDTO> bussinessList=new ArrayList<>();
        try {
            bussinessList=bussinessService.allBussiness(
                    BussinessStatusEnum.suceess.getCode()); //查询手游有效商家信息
        }catch (FanZoneException e){
            log.error("【查询所有商家信息】失败",e);
            map.put("error",e.getMessage());
            return ResultVOUntil.error(1,"【查询所有商家信息】失败");
        }
        log.info("id={}",id);
        map.put("bussinessList",bussinessList);
        return ResultVOUntil.success(map);
    }
}
